﻿using System;

namespace FDEE.Model
{
    public abstract class PileBase : MemberBase
    {
        protected double PileLength, Diameter, DowelLen;
        protected double Cover = 75;
        protected eSubType SubType;

        /// <summary>
        /// 桩基基类
        /// </summary>
        /// <param name="typeName"></param>
        /// <param name="pierNumber"></param>
        /// <param name="h">理论桩长</param>        
        public PileBase(string typeName, string pierNumber, eSubType st, double len, double dia) : base(typeName, pierNumber)
        {
            SubType = st;
            PileLength = len;
            Diameter = dia;
        }

        public override void SetConcreteClass()
        {
            ConcreteClass = eConcreteClass.C30;
        }
        public override void SetConcreteVolume()
        {
            ConcreteVolumn = Math.Round(Math.PI * Diameter * 0.001 * Diameter * 0.001 * 0.25 * PileLength, 3, MidpointRounding.AwayFromZero);
        }

        /// <summary>
        /// 螺旋箍筋由钢筋长度得螺旋长度--Bill20220519NewAdd
        /// </summary>
        /// <param name="L">钢筋长度</param>
        /// <param name="OD">外径</param>
        /// <param name="S">螺距</param>
        /// <param name="db">钢筋直径</param>
        /// <param name="Lap1">起点搭接</param>
        /// <param name="Lap2">终点搭接</param>
        /// <param name="Hook1">起点弯钩长度</param>
        /// <param name="Hook2">终点弯钩长度</param>
        /// <param name="AdditionalPerimeter">附加圈数</param>
        /// <returns></returns>
        public static double L2S(double L, double OD, double S, double db, double Lap1, double Lap2, double Hook1, double Hook2, double AdditionalPerimeter)
        {
            double dia = OD - db;
            double dL = Math.Sqrt(S * S + Math.PI * dia * Math.PI * dia);
            double Leff = L - 0.5 * Lap1 - 0.5 * Lap2 - Hook1 - Hook2 - AdditionalPerimeter * Math.PI * dia; // 剩余有效总长；
            double n = Leff / dL;
            return n * S;
        }
        /// <summary>
        /// 螺旋箍筋由螺旋长度得钢筋长度，与L2S互为反函数--Bill20220519NewAdd
        /// </summary>
        /// <param name="L">钢筋长度</param>
        /// <param name="OD">外径</param>
        /// <param name="S">螺距</param>
        /// <param name="db">钢筋直径</param>
        /// <param name="Lap1">起点搭接</param>
        /// <param name="Lap2">终点搭接</param>
        /// <param name="Hook1">起点弯钩长度</param>
        /// <param name="Hook2">终点弯钩长度</param>
        /// <param name="AdditionalPerimeter">附加圈数</param>
        /// <returns></returns>
        public static double S2L(double TotalS, double OD, double S, double db, double Lap1, double Lap2, double Hook1, double Hook2, double AdditionalPerimeter)
        {
            double n = TotalS / S;
            double dia = OD - db;
            double dL = Math.Sqrt(S * S + Math.PI * dia * Math.PI * dia);
            double Leff = dL * n;
            double L = Leff + 0.5 * Lap1 + 0.5 * Lap2 + Hook1 + Hook2 + AdditionalPerimeter * Math.PI * dia; // 剩余有效总长；
            return L;
        }

    }

}
